package com.tg.demo.seata.storage.controller;


import com.tg.demo.common.util.CommonResult;
import com.tg.demo.seata.storage.entity.SeataStorage;
import com.tg.demo.seata.storage.service.ISeataStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Rubble
 * @since 2020-05-26
 */
@RestController
@RequestMapping("/storage/seataStorage")
public class SeataStorageController {

    @Autowired
    private ISeataStorageService seataStorageService;


    @PostMapping("/deductStorage")
    public CommonResult deductStorage(@RequestParam("id") Integer id, @RequestParam("count") Integer count){

        SeataStorage storage = seataStorageService.getById(id);
        storage.setCount(storage.getCount()-count);
        boolean success = seataStorageService.updateById(storage);
        return CommonResult.sqlExecResult(success);
    }
}

